{% extends "oa/base.html" %}
{% load i18n static %}
{% block title %} 生产批次原料明细 {% endblock %}
{% block this_css %}
    <style>
        tbody > tr > td {
            white-space: nowrap
        }
    </style>
{% endblock %}
{% block content %}
    <section class="panel">
        <div class="panel-body">
            <form method="get" action="{{ request.path }}" class="form-inline">
                <div class="form-group">
                    <label for="date_before">统计截止日期:</label>
                    <input type="text" class="form-control" name="date_before" value="{{ request.GET.date_before }}"
                           id="date_before" placeholder="yyyy-mm-dd" data-date-format="yyyy-mm-dd">
                </div>
                <div class="form-group">
                    <label for="q">搜索:</label>
                    <input type="text" class="form-control" name="q" value="{{ request.GET.q }}" id="q">
                </div>
                <button type="submit" class="btn btn-info">重新统计</button>
                <a target="_blank" href="?excel=1&date_before={{ request.GET.date_before }}&q={{ request.GET.q }}"><span type="submit" class="btn btn-default">导出EXCEL</span></a>
            </form>
        </div>
    </section>
    <section class="panel">
        <div class="panel-body table-responsive">
            <table class="table table-striped table-bordered table-responsive">
                <thead>
                <tr>
                    <th colspan="15"><h3>砖巷科技生产成本统计</h3></th>
                </tr>
                <tr>
                    <th>酿造日期</th>
                    <th>酿造批次</th>
                    <th>酒款名称</th>
                    <th>状态</th>
                    <th class="text-center">投量（L）</th>
                    <th class="text-center">成本合计(元)</th>
                    <th>投料日期</th>
                    <th>批次号</th>
                    <th>投料形式</th>
                    <th>物料代码</th>
                    <th>物料名称</th>
                    <th class="text-center">单位</th>
                    <th class="text-center">使用数量</th>
                    <th class="text-center">单价（元）</th>
                    <th class="text-center">小计（元）</th>
                </tr>
                </thead>
                <tbody>
                {% for product_batch, value in data.product_batch_data.items %}
                    <tr>
                        <td rowspan="{{ value.rowspan }}">{{ value.start_date|date:'Y-m-d' }}</td>
                        <td rowspan="{{ value.rowspan }}">{{ product_batch }}</td>
                        <td rowspan="{{ value.rowspan }}">{{ value.product_name }}</td>
                        <td rowspan="{{ value.rowspan }}">{{ value.product_state }}</td>
                        <td class="text-center" rowspan="{{ value.rowspan }}">{{ value.total_volume }}</td>
                        <td class="text-center" rowspan="{{ value.rowspan }}"> {{ value.material_cost|floatformat:'2' }}</td>
                    </tr>
                    {% for material in value.material_list %}
                        <tr>
                            <td>{{ material.record_date|date:'Y-m-d' }}</td>
                            <td>{{ material.stage_code }}</td>
                            <td>{{ material.stage }}</td>
                            <td>{{ material.material_code }}</td>
                            <td>{{ material.material_name }}（{{ material.material_batch_code }}）</td>
                            <td class="text-center">{{ material.unit }}</td>
                            <td class="text-center">
                                {{ material.amount|floatformat:'2' }}</td>
                            <td class="text-center">
                                {{ material.unit_cost|floatformat:'2' }}</td>
                            <td class="text-center">{{ material.cost|floatformat:'2' }}</td>
                        </tr>
                    {% endfor %}
                {% endfor %}
                </tbody>
            </table>
        </div>
    </section>
{% endblock %}
